'use strict';

const Controller = require('egg').Controller;

class InfoController extends Controller {
    async index() {
        let {ctx,service} = this;
        let {id} = ctx.query;
        if(id){
            let target = await service.info.index(id);
            ctx.body = {
                code:1,
                data:target[0]
            }
        }else{
            ctx.body = {
                code:2,
                msg:'参数有误'
            }
        }
    }
    async update(){
        let {ctx,service} = this;
        let {sign,birth,sex,address} = ctx.request.body;
        let {id} = ctx.params;
        if(id){
            try{
                await service.info.update(sign,birth,sex,address,id);
                ctx.body = {
                    code:1,
                    msg:'修改成功'
                }
            }catch(e){
                ctx.body = {
                    code:0,
                    msg:e
                }
            }
        }else{
            ctx.body = {
                code:2,
                msg:'参数有误'
            }
        }
    }
}

module.exports = InfoController;
